import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path:'/',
    redirect:'/home'
  },
  {
    path: '/home',
    name: 'home',
    redirect:'/home/index',
    component: ()=> import('../views/HomeView.vue'),
    children:[
      // 首页
      {
        path:'index',
        name:'index',
        component:() => import('../views/Index.vue'),
        meta:{
          title:'首页 —苏富比拍卖',
          keepalive:true
        }
      },
      // 拍卖页
      {
        path:'sale',
        name:'sale',
        component:() => import('../views/Sale.vue'),
        meta:{
          title:'拍卖 -苏富比拍卖'
        },
        redirect:'/home/sale/daySale',
        children:[
          // 拍卖日程页
          {
            path:'daySale',
            name:'daySale',
            component:() => import('../views/DaySale.vue'),
            meta:{
              title:'拍卖日程 -苏富比拍卖'
            }
          },
          // 拍卖结果页
          {
            path:'SaleResult',
            name:'SaleResult',
            component:() => import('../views/SaleResult.vue'),
            meta:{
              title:'拍卖结果 -苏富比拍卖',
              keepalive:true
            }
          }
        ]
      },
      //发现页
      {
        path:'seed',
        name:'seed',
        component: () => import('../views/Seed.vue'),
        meta:{
          title:'发现 -苏富比拍卖'
        },
        redirect:'/home/seed/zixun?family=daySale',
        children:[
          {
            path:'zixun',
            name:'zixun',
            component:()=>import('../views/Seedzixun.vue'),
            meta:{
              title:'发现 -资讯'
            }
          }
        ]
      },
      // 我的个人中心页
      {
        path:'me',
        props:true,
        name:'me',
        component:() => import('../views/Me.vue'),
        meta:{
          title:'我的个人中心'
        },
      }
    ],
  },
  // 注册页
  {
    path:'/register',
    name:'register',
    component:() => import('../views/Register.vue'),
    meta:{
      title:'注册 —苏富比'
    }
  },
  // 登录页
  {
    path:'/login',
    name:'login',
    component:()=>import('../views/Login.vue'),
    meta:{
      title:'登录 —苏富比'
    }
  },
  // 找回密码页
  {
    path:'/nopwd',
    name:'nopwd',
    redirect:'/nopwd/tabs',
    component:() => import('../views/Nopwd.vue'),
    meta:{
        title:'找回密码'
    },
    children:[
      // 选项页
      {
        path:'tabs',
        name:'tab',
        component:()=> import('../views/NopwdTabs.vue'),
        meta:{
          title:'找回密码',
        }
      },
      // 通过邮箱找回密码
      {
        path:'emailpwd',
        name:'emailpwd',
        component:() => import('../views/Emailpwd.vue'),
        meta:{
          title:'通过邮箱找回密码'
        }
      },
      // 通过手机号找回密码
      {
        path:'phonepwd',
        name:'phonepwd',
        component:()=>import('../views/Phonepwd.vue'),
        meta:{
          title:'通过手机号找回密码'
        }
      }
    ]
  },
  // 拍品详情页
  {
    path:'/auction_details/:pid',
    props:true,
    name:'auction_details',
    component:() => import('../views/Auction.vue'),
    meta:{
      title:'拍品详情页',
    }
  },
  // 搜索页
  {
    path:'/search',
    name:'search',
    component:()=> import('../views/Search.vue'),
    meta:{
      title:'搜索',
      keepalive:true
    }
  },
  // 新闻详情页
  {
    path:'/newsDetails',
    name:'newsDetails',
    component:()=> import('../views/NewDetails.vue'),
    meta:{
      title:'新闻详情页'
    }
  },
  // 客服页
  {
    path:'/kefu',
    name:'kefu',
    component:() => import('../views/Kefu.vue'),
    meta:{
      title:'在线客服'
    }
  },
  // 用户资料页
  {
    path:'/base_user',
    name:'base_user',
    component:() => import('../views/Ucenter.vue'),
    meta:{
      title:'用户中心 ——苏富比'
    }
  },
  // 确认订单页
  {
    path:'/order/:pid',
    props:true,
    name:'order',
    component:() => import('../views/Order.vue'),
    meta:{
      title:'确认订单'
    }
  },
  // 收货地址页
  {
    path:'/address',
    name:'Address',
    props:true,
    redirect:'/address/show_address/:userId',
    component:() => import('../views/Address.vue'),
    children:[
      // 查看收货地址
      {
        path:'show_address/:userId',
        props:true,
        name:'show_address',
        component:() => import('../views/ShowAddress.vue'),
        meta:{
          title:'收货地址'
        }
      }
    ],
    meta:{
      title:'收货地址'
    }
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes,
  scrollBehavior(to,from,savedPosition){
    if(to.name == 'auction_details'){
      document.documentElement.scrollTop=document.body.scrollTop=0
    }
    return savedPosition
  }
})
router.beforeEach((to,from,next)=>{
  document.title=to.meta.title
  next()
})
export default router
